package com.pingan.springboot_es_api.controller;

import com.pingan.springboot_es_api.domain.Demo;
import com.pingan.springboot_es_api.exception.MyException;
import com.pingan.springboot_es_api.service.DemoService;
import io.swagger.annotations.ApiOperation;
import org.frameworkset.elasticsearch.entity.ESDatas;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Kay on 2018/10/28
 */
@RestController
public class DemoController {
    @Autowired
    private DemoService demoService;

    @ApiOperation(value="获取demo", notes="获取demo by id")
    @GetMapping(value = "/searchbyid")
    public Demo SearchById(@RequestParam("id") String id) throws MyException{
        try {

            return demoService.SearchById(id);
        }catch (Exception ex)
        {
            throw new MyException(ex.getMessage());
        }
    }

    @ApiOperation(value="获取所有demo", notes="获取demo  all")
    @GetMapping(value = "/searchall")
    public ESDatas<Demo> SearchAll(){
        return demoService.SearchAll();
    }


}
